import { ApiProperty } from '@nestjs/swagger';
import { IsDate, IsEnum, IsInt, IsOptional, IsString, IsNotEmpty, IsNumber } from 'class-validator';
import { CommonStatus } from '~/common/entity/common.entity';
import { Type } from 'class-transformer';
import { MissionType } from './mission.model';
import { PagerDto } from '~/common/dto/pager.dto';

export class CreateMissionDto {
  @ApiProperty({ description: '任务名称', default: '' })
  @IsString()
  name: string;

  @ApiProperty({ description: '任务描述', default: '' })
  @IsString()
  description: string;

  @ApiProperty({ description: '任务开始时间', default: null })
  @IsDate()
  @IsOptional()
  @Type(() => Date)
  startDate?: Date;

  @ApiProperty({ description: '任务结束时间', default: null })
  @IsDate()
  @IsOptional()
  @Type(() => Date)
  endDate?: Date;

  @ApiProperty({ description: '任务类型', default: MissionType.CATALOG })
  @IsEnum(MissionType)
  missionType: MissionType;

  @ApiProperty({ description: '任务类型关联数据', default: null })
  @IsString()
  @IsOptional()
  missionRelatedData?: string;

  @ApiProperty({ description: '是否为无限期活动', default: CommonStatus.NO })
  @IsEnum(CommonStatus)
  @Type(() => Number)
  isPerpetual: CommonStatus;

	@ApiProperty({description: '关联积分规则ID', required: true})
	@IsInt()
	@Type(() => Number)
	pointsRuleId: number
}

export class MissionRecordDto {
	// missionType | diseaseId | relatedId | score
	@ApiProperty({ description: '任务类型', required: true })
	@IsEnum(MissionType, { message: '任务类型不正确' })
	missionType: MissionType;

	@ApiProperty({ description: '疾病ID', required: false })
	@IsInt({ message: '疾病ID必须为整数' })
	@IsOptional()
	diseaseId?: number;

	@ApiProperty({ description: '关联ID', required: true })
	@IsString({ message: '关联ID必须为字符串' })
	relatedId: string;

	@ApiProperty({ description: '分数', required: false })
	@IsInt({ message: '分数必须为整数' })
	@IsOptional()
	score?: number;
}

export class SearchMissionDto extends PagerDto {
  @ApiProperty({ description: '任务名称', required: false })
  @IsString()
  @IsOptional()
  name?: string;

  @ApiProperty({ description: '任务类型', enum: MissionType, required: false })
  @IsEnum(MissionType)
  @IsOptional()
  type?: MissionType;
}
